﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;

namespace Milo.Tests
{
    using Framework;
    using Mock;
    using Mock.Controls;

	[TestFixture]
	public class ArrayNamingTests
	{
		[Test]
		public void TestStringArray()
		{
			string[] a = new string[] { "one", "two", "three" };

			ControlList<string, FieldControl<string>> ac = new ControlList<string, FieldControl<string>>(a);

			Assert.AreEqual(3, a.Count());
			Assert.AreEqual("one", ac[0].Value);
			Assert.AreEqual("two", ac[1].Value);
			Assert.AreEqual("three", ac[2].Value);
			Assert.AreEqual("[0]", ac[0].ModelID);
		}

		[Test]
		public void TestStringArrayWithPrefix()
		{
			string[] a = new string[] { "one", "two", "three" };

			ControlList<string, FieldControl<string>> ac = new ControlList<string, FieldControl<string>>("array", a);

			Assert.AreEqual("array[0]", ac[0].ModelID);
		}
		[Test]
		public void TestStringArrayInContainer()
		{
			ArrayContainer ac = new ArrayContainer();
			ac.StringArray = new string[] { "one", "two", "three" };

			ArrayContainerControl control = new ArrayContainerControl(ac);

			Assert.AreEqual("one", control.StringArray[0].Value);
			Assert.AreEqual("StringArray[1]", control.StringArray[1].ModelID);
		}

		[Test]
		public void TestStringArrayInContainerWithPrefix()
		{
			ArrayContainer ac = new ArrayContainer();
			ac.StringArray = new string[] { "one", "two", "three" };

			ArrayContainerControl control = new ArrayContainerControl("obj", ac);

			Assert.AreEqual("one", control.StringArray[0].Value);
			Assert.AreEqual("obj.StringArray[1]", control.StringArray[1].ModelID);
		}

		[Test]
		public void TestSimpleTypeArrayInContainer()
		{
			ArrayContainer ac = new ArrayContainer();
			ac.SimpleTypeArray = new SimpleType[] { new SimpleType("one", 1, 100M), new SimpleType("two", 2, 200M) };

			ArrayContainerControl control = new ArrayContainerControl(ac);

			Assert.AreEqual("one", control.SimpleTypeArray[0].StringValue.Value);
			Assert.AreEqual("SimpleTypeArray[1].StringValue", control.SimpleTypeArray[1].StringValue.ModelID);
		}

		[Test]
		public void TestSimpleTypeArrayInContainerWithPrefix()
		{
			ArrayContainer ac = new ArrayContainer();
			ac.SimpleTypeArray = new SimpleType[] { new SimpleType("one", 1, 100M), new SimpleType("two", 2, 200M) };

			ArrayContainerControl control = new ArrayContainerControl("obj", ac);

			Assert.AreEqual("one", control.SimpleTypeArray[0].StringValue.Value);
			Assert.AreEqual("obj.SimpleTypeArray[1].StringValue", control.SimpleTypeArray[1].StringValue.ModelID);
		}

		[Test]
		public void TestSimpleTypeArrayWithNoModel()
		{
			ArrayContainerControl acc = new ArrayContainerControl();

			Assert.AreEqual("SimpleTypeArray_2", acc.SimpleTypeArray[2].ClientID);
			Assert.AreEqual("SimpleTypeArray_2_DecimalValue", acc.SimpleTypeArray[2].DecimalValue.ClientID);
		}
	}
}
